package com.me.study.javaBasic.dataType;

/**
 *
 *
 * @author ME
 * @date 2017年4月25日 下午2:30:34
 */
public class TestString {

	public static void main(String[] args) {
		System.out.println("\n负数表示升序:" + "ab".compareTo("ac"));

		// 测试 String.length()
		System.out.println("\n============测试 String.length()============");
		String str = "asdaf";
		System.out.println(str.length());
		System.out.println(str.substring(0, 4));

		System.out.println("\ns1 == \"abc\"");
		String s1 = "abc";
		System.out.println(s1 == "abc");

		System.out.println("\ns2 == \"abc\"");
		String s2 = new String("abc");
		System.out.println(s2 == "abc");

		System.out.println("\ns3 == s2");
		String s3 = new String("abc");
		System.out.println(s3 == s2);

		System.out.println("\ns4 == \"abc\"");
		String s4 = "ab" + "c";
		System.out.println(s4 == "abc");

		// 注意:这里s用final修饰，相当于一个常量
		System.out.println("\ns5 == \"abc\"");
		final String s = "ab";
		String s5 = s + "c";
		System.out.println(s5 == "abc");

		// `s1 + s2` 相当于 StringBuilder.append().toString()
		System.out.println("\ns6 == \"abc\"");
		String ab = "ab";
		String c = "c";
		String s6 = ab + c;
		System.out.println(s6 == "abc");

		System.out.println("\nstr7 == \"abc\"");
		String str7 = "abcd".substring(0, 3);
		System.out.println(str7 == "abc");
	}

}
